/*
 * (C) APUE
 * Judge if can access a file
 * usage: ./access dumpfile
 * In root and sheng seperately
 */

#include "apue.h"
#include <fcntl.h>

int main(int argc, char *argv[])
{
	if (argc != 2)
		err_quit("usage: a.out <pathname>");

	if (access(argv[1], R_OK) < 0)
		err_msg("access error for %s", argv[1]);
	else
		printf("read access OK\n");

	if (open(argv[1], O_RDONLY) < 0)
		err_quit("open error for %s", argv[1]);
	else
		printf("open for reading %s\n", argv[1]);

	return 0;
}
